#!/bin/sh

#一行一行打印


usage()
{
	echo "Today's date is `date`"
	echo "The software's usage"
	echo "./IPv6G IPv6"
}

ipv6()
{
	echo "请选择策略，A或者B，首选为B"
	read scheme
	if [ "$scheme" = "B" ]; then
		B
	else
		A
	fi
}

B() 
{
	echo "首选B策略"
	echo "ASN+IPv4Prefix+随机数"

	asn_j=`expr 1024 "*" 8`
	asn_i=`echo "obase=16; $asn_j" | bc`
#	echo "$asn_i"

	echo "请输入一个IPv4的前缀和IPv4前缀长度"
#IPv6前缀长度等于IPv4长度的2倍
	read IPv4P IPv4L
	IPv6L=`expr $IPv4L "*" 2`
	randomL=`expr $IPv4L - 16`
	echo "请输入一个 $randomL bit的随机值"
	read random
	echo "$asn_i:$i:$random/$IPv6L"
		
}

A()
{
	echo "A group"
}

ipv4()
{
	echo "IPv4 perfix"
#创建存储表的文件
	if [ -e yiyi ]; then
		echo "已经有yiyi"
		echo "是否删除原来的yiyi，yes或者no"
		read y_or_n
		case "$y_or_n" in
			y*) rm yiyi
			    echo "已经删除yiyi";;
			n*) echo "no";;
		esac
	else
		touch yiyi
	fi
#创建表	
	echo 请输入i的值
	read i
	j=0

	while [ "$j" -lt "$i" ]; do
		echo -e $j >> yiyi
		j=`expr $j + 1`
	done
}

case "$1" in
	IPv4) echo "IPv4 table"
	      ipv4;;
	IPv6) echo "IPv6 table"
	      ipv6;;
	* | h* | H*)    usage;;
esac

exit 0
